package com.chinaums.itp.demo;

import com.chinaums.itp.client.ItpMessage;

import java.util.Map;

/**
 * Created on 2014/10/23.
 *
 * @author YaoFeng
 */
public class MessageUtils {

	private final static String LINE_SEPARATOR = "\n";

	public static String formatMessage(final ItpMessage itpMessage) {
		final StringBuilder builder = new StringBuilder();
		builder.append("tranCode = ").append(itpMessage.getTranCode()).append(LINE_SEPARATOR);
		builder.append("tranId = ").append(itpMessage.getTranId()).append(LINE_SEPARATOR);
		builder.append("tranTime = ").append(itpMessage.getTranTime()).append(LINE_SEPARATOR);
		final String sysTranId = itpMessage.getSysTranId();
		if (sysTranId != null) {
			builder.append("sysTranId = ").append(sysTranId).append(LINE_SEPARATOR);
		}
		final String sysTranDate = itpMessage.getSysDate();
		if (sysTranDate != null) {
			builder.append("sysTranDate = ").append(sysTranDate).append(LINE_SEPARATOR);
		}
		for (final Map.Entry<String, String> field : itpMessage) {
			builder.append(field.getKey()).append(" = ").append(field.getValue()).append(LINE_SEPARATOR);
		}
		return builder.toString();
	}
}
